﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChartEdit
{
    public class Clapper
    {
        public Clapper(Editor ed)
        {
            this.ed = ed;
        }
        private Editor ed;
        private int nextNoteIndex;
        private float nextNoteTime;

        public void Start()
        {
            nextNoteIndex = ed.OT.nextNIndex(ed.OT.GetOffset(ed.COffset), ed.noteTrack);
            if(ed.noteTrack!=null)
                nextNoteTime = ed.OT.GetTime(ed.noteTrack[nextNoteIndex].Offset);
        }

        public void Clap()
        {
            if (ed.COffset > nextNoteTime & ed.noteTrack != null)
            {
                nextNoteIndex++;
                if (nextNoteIndex < ed.noteTrack.Count())
                {
                    ed.song.Clap(ed.COffset-nextNoteTime);
                    nextNoteTime = ed.OT.GetTime(ed.noteTrack[nextNoteIndex].Offset);
                }
            }
        }


    }
}
